package com.kly.user.db.dao.impl;
import com.fqgj.common.base.AbstractBaseMapper;
import com.fqgj.common.utils.CollectionUtils;
import com.google.common.collect.Maps;
import com.kly.user.db.dao.UserConversationGroupDao;
import com.kly.user.db.entity.UserConversationGroupEntity;
import com.kly.user.dto.chatter.request.ConversationOPReq;
import com.kly.user.utils.ServiceUtils;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
* User: linqu
* Date: 2023-06-21
* Time: 10:43:12.833
*/

@Repository
public class UserConversationGroupDaoImpl extends AbstractBaseMapper<UserConversationGroupEntity> implements UserConversationGroupDao {

    @Override
    public UserConversationGroupEntity queryConversationGroup(ConversationOPReq req) {

        Map<String, Object> params = Maps.newHashMap();
        params.put("groupId", req.getUserGroupLabel());
        // 当前聊天用户
        params.put("userCodeFriend", req.getUserCodeFriend());
        final List<UserConversationGroupEntity> userConversationGroupEntities = this.selectByParams(params);
        if (CollectionUtils.isEmpty(userConversationGroupEntities)) {
            return new UserConversationGroupEntity();
        }
        return userConversationGroupEntities.get(0);
    }

    @Override
    public UserConversationGroupEntity queryUserGroup(String chatterUserId, String modelUserId, String userId) {

        Map<String, Object> params = Maps.newHashMap();
        params.put("groupId", modelUserId);
        params.put("userCodeFriend", userId);
        params.put("modelUserCode", modelUserId);
        params.put("chatterUserCode", chatterUserId);
        params.put("deleted", 0);
        params.put("status", 1);
        final List<UserConversationGroupEntity> userConversationGroupEntities = this.selectByParams(params);
        if (CollectionUtils.isEmpty(userConversationGroupEntities)) {
            return new UserConversationGroupEntity();
        }
        return userConversationGroupEntities.get(0);
    }

    @Override
    public UserConversationGroupEntity queryUserGroupByCode(String chatterUserId, String modelUserId, String userId) {

        Map<String, Object> params = ServiceUtils.getParams();
        params.put("groupId", modelUserId);
        params.put("userCodeFriend", userId);
        params.put("modelUserCode", modelUserId);
        params.put("chatterUserCode", chatterUserId);
        final List<UserConversationGroupEntity> userConversationGroupEntities = this.selectByParams(params);
        if (CollectionUtils.isEmpty(userConversationGroupEntities)) {
            return null;
        }
        return userConversationGroupEntities.get(0);
    }
}